home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / utilities / guide / stripguide.lha / stripguide.l < prev    next >
Encoding:
Text File  |  1994-06-30  |  2.6 KB  |  157 lines

  1. /*    ex:set tabstop=4:
  2. **    Flex source for stripping out amigaguide stuff
  3. **    Athens 30/Jun/1994 by PA (Pantelis Antoniou)
  4. **    This is public domain so do with it whatever you like, just don't
  5. **    bother me if it just happens to blow in your face ;-) (Just kidding).
  6. **    Anyway feel free to modify it as you see fit, it's nothing much really.
  7. */
  8.  
  9. %{
  10.  
  11. #include <fcntl.h>
  12.  
  13. #define MODE_OUTSIDE        1
  14. #define MODE_SKIPLINE        2
  15. #define MODE_PRINT            3
  16. #define MODE_SKIPBRACE        4
  17. #define MODE_INSTRING        5
  18.  
  19. static int mode=MODE_OUTSIDE;
  20. static int fancy=0;
  21.  
  22. #define BOLDFACE            (printf("\033[1m"))
  23. #define UNDERLINE            (printf("\033[4m"))
  24. #define NORMAL                (printf("\033[0m"))
  25. #define FORMFEED            (printf("\f\r"))
  26.  
  27. %}
  28.  
  29. NODE        @[nN][oO][dD][eE]
  30. ENDNODE        @[eE][nN][dD][nN][oO][dD][eE]
  31. GUIDESTUFF    @[a-zA-Z]
  32. FGHIGHLIGHT    @\{[fF][gG][ \t]+[hH][iI][gG][hH][lL][iI][gG][hH][tT]
  33. FGTEXT        @\{[fF][gG][ \t]+[tT][eE][xX][tT]
  34. FANCYSTART    @\{[a-tv-zA-TV-Z]\}
  35. FANCYEND    @\{[uU][a-tv-zA-TV-Z]\}
  36. STRING        @\{\"
  37.  
  38. %%
  39.  
  40. ^{NODE}            mode = MODE_SKIPLINE;
  41.  
  42. ^{ENDNODE}        {
  43.                     if (fancy) FORMFEED;
  44.                     mode = MODE_OUTSIDE;
  45.                 }
  46.  
  47. {FGHIGHLIGHT}    {
  48.                     if (fancy) BOLDFACE;
  49.                     mode = MODE_SKIPBRACE;
  50.                 }
  51.  
  52. {FGTEXT}        {
  53.                     if (fancy) NORMAL;
  54.                     mode = MODE_SKIPBRACE;
  55.                 }
  56.  
  57. {FANCYSTART}    if (fancy) BOLDFACE;
  58.  
  59. {FANCYEND}        if (fancy) NORMAL;
  60.  
  61. {STRING}        {
  62.                     mode = MODE_INSTRING;
  63.                     if (fancy) UNDERLINE;
  64.                 }
  65.  
  66. \"                {
  67.                     if (mode==MODE_INSTRING)
  68.                     {
  69.                         mode=MODE_SKIPBRACE;
  70.                         if (fancy) NORMAL;
  71.                     }
  72.                     else if (mode==MODE_PRINT)
  73.                         ECHO;
  74.                 }
  75.  
  76. \}                {
  77.                     if (mode==MODE_SKIPBRACE)
  78.                         mode = MODE_PRINT;
  79.                     else
  80.                         ECHO;
  81.                 }
  82.  
  83. {GUIDESTUFF}    mode = MODE_SKIPLINE;
  84.  
  85. .                {
  86.                     if (mode==MODE_PRINT || mode==MODE_INSTRING)
  87.                         ECHO;
  88.                 }
  89.  
  90. "\n"            {
  91.                     if (mode==MODE_PRINT)
  92.                         ECHO;
  93.                     else if (mode==MODE_SKIPLINE)
  94.                         mode = MODE_PRINT;
  95.                 }                    
  96.  
  97. %%
  98.  
  99. int yyerror(char *s)
  100. {
  101.     return(0);
  102. }
  103.  
  104. int main(int argc,char *argv[])
  105. {
  106.     extern int yylex(void);
  107.     char *infile;
  108.     char *outfile;
  109.     int i;
  110.  
  111.     if (argc>1 && *argv[1]=='?')
  112.     {
  113.         fprintf(stderr,"Usage : StripGuide [-fancy] [<infile>] [<outfile>]\n");
  114.         return(5);
  115.     }
  116.     i=1;
  117.     if (argc>1 && *argv[1]=='-' && argv[1][1]=='f')
  118.     {
  119.         fancy=1;
  120.         i++;
  121.     }
  122.     for (infile=outfile=NULL; i<argc; i++)
  123.     {
  124.         if (!infile)
  125.             infile = argv[i];
  126.         else if (!outfile)
  127.             outfile = argv[i];
  128.         else
  129.             break;
  130.     }
  131.  
  132.     if (infile)
  133.     {
  134.         if (!freopen(infile,"r",stdin))
  135.         {
  136.             fprintf(stderr,"*** ERROR *** Unable to open input file %s\n",infile);
  137.             return(10);
  138.         }
  139.     }
  140.     if (outfile)
  141.     {
  142.         if (!freopen(outfile,"w",stdout))
  143.         {
  144.             fprintf(stderr,"*** ERROR *** Unable to open output file %s\n",outfile);
  145.             return(10);
  146.         }
  147.     }
  148.         
  149.     NORMAL;
  150.  
  151.     (void) yylex();
  152.  
  153.     NORMAL;
  154.  
  155.     return(0);
  156. }
  157.